/*  -*- mode: c++; coding: utf-8; c-file-style: "stroustrup"; -*-

    Copyright 2008 Asier Aguirre <asier.aguirre@gmail.com>
    This file is part of Intromit.

    Intromit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Intromit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Intromit.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef PYEMBED_INTROMIT_HH
#define PYEMBED_INTROMIT_HH

//#include <stdlib.h>
#include <Python.h>
#include "readcommand.hh"

class readcommand;
class string;
class pymetadata_global;

class pyintromit_embed
{
    string *str;
    readcommand *rc;
    PyObject *main;  // stores __main__ module

    // internal commands list
    static command_struct command_list[];

    // behavior of intromit
    int exit_immediately, readline, quiet, reload, cl_narg;
    char *framework_filename, **cl_argv;

    // PRIVATE FUNCTIONS
    static char **completion_static(const char *text, int start, int end, char *complete_text, void *obj);
    char **completion(const char *text, int start, int end, char *complete_text);
    PyObject *extract_object(const char *name);
    bool is_internal_command(const char *command);
    void print_command_line_help();

    // internal commands
    static int ic_ref(int n_param, char **param, pyintromit_embed *ctx);
    static int ic_load(int n_param, char **param, pyintromit_embed *ctx);
    static int ic_reload(int n_param, char **param, pyintromit_embed *ctx);
    static int ic_ls(int n_param, char **param, pyintromit_embed *ctx);
    static int ic_mkdir(int n_param, char **param, pyintromit_embed *ctx);
    static int ic_cd(int n_param, char **param, pyintromit_embed *ctx);
    static int ic_pwd(int n_param, char **param, pyintromit_embed *ctx);

public:

    pyintromit_embed();
    ~pyintromit_embed();

    // ** INITIALIZATION **

    // init python context or false
    bool init(int narg=0, char **arg=NULL);

    // ** STATUS FUNCTIONS **
    inline bool get_quiet() {return quiet;}

    // ** COMMAND INSERTION **

    // init interactive command insertion, returns false in case of error
    bool command_line_init(const char *prompt=NULL, const char *history_file=NULL);

    // synchronous operation, so calling this functions periodically is required
    // returns false when interaction closed by user (ctrl+d)
    bool command_line_refresh();

    // free interactive session and its resources
    bool command_line_finish();

    // insert a command
    bool command(const char *command);
};

#endif

/* Offline metadata attributes:

   @metadata_attrs(
	pyintromit_embed:
					~select
   )
*/
